package com.heima.admin.controller.v1;

import com.heima.admin.service.AdChannelService;
import com.heima.api.admin.AdChannelControllerApi;
import com.heima.model.admin.dtos.ChannelDto;
import com.heima.model.admin.pojos.AdChannel;
import com.heima.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description: 描述
 * @author：Bing
 * @date：2021/3/29 16:28
 * @version：1.0
 */
@RestController
@Api(tags = "频道管理")
@RequestMapping("/api/v1/channel")
public class AdChannelController implements AdChannelControllerApi {

    @Autowired
    private AdChannelService channelService;

    @ApiOperation("查询频道")
    @PostMapping("/list")
    @Override
    public ResponseResult findByNameAndPage(@RequestBody ChannelDto dto) {
        return channelService.findByNameAndPage(dto);
    }

    @ApiOperation("新增频道")
    @PostMapping("/save")
    @Override
    public ResponseResult save(@RequestBody AdChannel channel) {
        return channelService.insert(channel);
    }

    /**
     * 修改
     */
    @ApiOperation("修改频道")
    @Override
    @PostMapping("/update")
    public ResponseResult update(@RequestBody AdChannel adChannel) {
        return channelService.update(adChannel);
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @ApiOperation("删除频道")
    @Override
    @GetMapping("/del/{id}")
    public ResponseResult deleteById(@PathVariable("id") Integer id) {
        return channelService.deleteById(id);
    }

    @ApiOperation("查询所有频道")
    @GetMapping("/channels")
    @Override
    public ResponseResult findAll() {
        List<AdChannel> list = channelService.list();
        return ResponseResult.okResult(list);
    }
}
